'use strict';

const Controller = require('egg').Controller;
const { getCookieValue } = require('../public/processCookies');
/**
* @controller ConfigController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class ConfigController extends Controller {
  async single() {
    /**
        * @summary configsingle
        * @description configsingle
        * @router get /configsingle
        */
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    const result = await this.ctx.service.config.single(tid);
    this.ctx.body = {
      data: result,
    };
  }
  async edit() {
    /**
        * @summary configedit
        * @description configedit
        * @router post /configedit
        * @request body config value 传入参数
        */
    const params = this.ctx.request.body;
    const configResult = await this.ctx.model.Config.findOne({ where: { id: params.id } });
    await this.ctx.service.config.edit(params);
    global.log.desc = 'config exit';
    global.log.before = `{days:${configResult.days},flag:${configResult.flag},refreshtime:${configResult.refreshtime}}`;
    global.log.after = `{days:${params.days},flag:${params.flag},refreshtime:${params.refreshtime}}`;
    this.ctx.body = {
      msg: 'edit successful',
    };
  }

  async getDashBoard(){
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    console.log(tid)
    let unRegisterONU = await this.ctx.model.OnuFind.find({tid:tid})
    let RegisterOlt = await this.ctx.model.Olt.find({tid:tid})
    let OnLineOlt = await this.ctx.model.Olt.find({tid:tid,onlineState:'true'})
    let onLineOnu = await this.ctx.model.OnuList.find({tid,status:"working"})
    let offLineOnu = await this.ctx.service.config.finOffLineOnu(tid)
   
   console.log(offLineOnu)
   this.ctx.body = {
     msg:{unRegisterONU,RegisterOlt,OnLineOlt,offLineOnu,onLineOnu}
   }
  }
}

module.exports = ConfigController;
